home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / clipboard / clipgl.c < prev    next >
C/C++ Source or Header  |  1993-12-07  |  4KB  |  144 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "mg.h"
  4. #include "mggl.h"
  5. #include "geom.h"
  6. #include "mibload.h"
  7. #include "clip.h"
  8. #include <gl/gl.h>
  9. #include <X11/Xirisw/GlxMDraw.h>
  10.  
  11. void wininit(Widget, XtPointer,
  12.     GlxDrawCallbackStruct *);
  13. void winexpose(Widget, XtPointer,
  14.     GlxDrawCallbackStruct *);
  15.  
  16. extern Geom *theObject;
  17.  
  18. ColorA white = {1.0, 1.0, 1.0, 1.0};
  19. ColorA red = {1.0, 0, 0, 1.0};
  20. ColorA darkgray = {0.2, 0.2, 0.2};
  21. ColorA darkblue = {0, 0, .2, 1.0};
  22. Point lightpos1 = {1, .3, .7, 0.0};
  23. Point lightpos2 = {-0.5, 1.0, 0.5, 0.0};
  24. ColorA lightcol2 = {0.6, 0.6, 0.6, 1.0};
  25. Point lightpos3 = {0.0, -2.0, 1.0, 0.0};
  26. ColorA lightcol3 = {0.4, 0.4, 0.4, 1.0};
  27.  
  28.  
  29. Camera        *theCamera;
  30. Appearance    *theAppearance;
  31. LmLighting    *lightingModel;
  32. LtLight        *theLight;
  33. mgcontext    *mgctx;
  34.  
  35. void clipboard_init(Widget parent)
  36. {
  37.   int           n;
  38.   Arg           args[20];
  39.   Widget    MG_DrawArea;
  40.  
  41.   static GLXconfig db_rgb_desc[] = {
  42.    { GLX_NORMAL, GLX_RGB, TRUE},
  43.    { GLX_NORMAL, GLX_DOUBLE, FALSE},
  44.    { GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG },
  45.    { 0,0,0 }
  46.   };
  47.  
  48.   n = 0;
  49.   XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  50.   XtSetArg (args[n], XmNleftOffset, 110);n++;
  51.   XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  52.   XtSetArg (args[n], XmNtopOffset, 6);n++;
  53.   XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  54.   XtSetArg (args[n], XmNrightOffset, 7);n++;
  55.   XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  56.   XtSetArg (args[n], XmNbottomOffset, 8);n++;
  57.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  58.   XtSetArg (args[n], GlxNglxConfig, db_rgb_desc); n++;
  59.  
  60.   MG_DrawArea = GlxCreateMDraw(parent, "mg", args, n);
  61.  
  62.   XtManageChild(MG_DrawArea);
  63.  
  64.   mmode(MVIEWING);
  65.  
  66.   XtAddCallback(MG_DrawArea, GlxNginitCallback, wininit, 0);
  67.   XtAddCallback(MG_DrawArea, GlxNexposeCallback, winexpose, 0);
  68.  
  69.   mgdevice_GL();
  70.  
  71.   theObject = NULL;
  72.  
  73.   theCamera = CamCreate( CAM_FOV, 40.0, CAM_END );
  74.  
  75.   lightingModel = LmCreate( LM_AMBIENT, &darkgray,
  76.                 LM_REPLACELIGHTS, 1,
  77.                 LM_END);
  78.  
  79.   theLight = LtCreate( LT_COLOR, &white,
  80.                LT_POSITION, &lightpos1,
  81.                LT_INTENSITY, 1.0, LT_END);
  82.  
  83.   LtAppend(lightingModel, theLight);
  84.  
  85.   theLight = LtCreate( LT_COLOR, &lightcol2,
  86.                LT_POSITION, &lightpos2,
  87.                LT_INTENSITY, 1.0, LT_END);
  88.  
  89.   LtAppend(lightingModel, theLight);
  90.  
  91.   theLight = LtCreate( LT_COLOR, &lightcol3,
  92.                LT_POSITION, &lightpos3,
  93.                LT_INTENSITY, 1.0, LT_END);
  94.  
  95.   LtAppend(lightingModel, theLight);
  96.  
  97.   theAppearance = ApCreate( AP_DO, APF_FACEDRAW | APF_SHADING | APF_EDGEDRAW,
  98.                 AP_MtSet, MT_Kd, 1.0, MT_DIFFUSE, &white, MT_END,
  99.                 AP_LGT, lightingModel,
  100.                 AP_SHADING, APF_FLAT, AP_END);
  101.  
  102.   mgctx = mgctxcreate(MG_GLXDISPLAY, XtDisplay(MG_DrawArea),
  103.           MG_GLWINID, XtWindow(MG_DrawArea),
  104.           MG_CAMERA, theCamera, MG_BACKGROUND, &darkblue,
  105.           MG_APPEAR, theAppearance, MG_END);
  106.  
  107. /*  theObject = GeomLoad("dodec.quad");*/
  108.  
  109. }
  110.  
  111. void wininit(Widget w, XtPointer stuff, GlxDrawCallbackStruct *data)
  112. {
  113.  
  114.   GLXwinset(XtDisplay(w), data->window);
  115.   fprintf(stderr,"init!\n");
  116. /*  color(GREEN);
  117.   clear();*/
  118.  
  119. }
  120.  
  121. void redraw(Widget w)
  122. {
  123.   GLXwinset(XtDisplay(w), XtWindow(w));
  124.   mgreshapeviewport();
  125.   mgworldbegin();
  126.   GeomDraw(theObject);
  127.   mgworldend();
  128.   gflush();
  129. }
  130.  
  131.  
  132. void winexpose(Widget w, XtPointer stuff, GlxDrawCallbackStruct *data)
  133. {
  134.   static float p1[] = {0.0, 0.0, 0.0};
  135.   static float p2[] = {800.0, 800.0, 0.0};
  136.  
  137.   GLXwinset(XtDisplay(w), data->window);
  138.   mgreshapeviewport();
  139.   mgworldbegin();
  140.   GeomDraw(theObject);
  141.   mgworldend();
  142.   gflush();
  143. }
  144.